package net.gyapp.markim.core.entity;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import net.gyapp.markim.module.contact.adapter.ContactsAdapter;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.ToMany;

import java.io.Serializable;
import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import net.gyapp.markim.dao.DaoSession;
import net.gyapp.markim.dao.MemberEntityDao;
import net.gyapp.markim.dao.GroupEntityDao;


/**
 * Auther:  winds
 * Email:   heardown@163.com
 * Date:    2018/7/19.
 * Desc:    群
 */
@Entity
public class GroupEntity implements IEntity, MultiItemEntity, Serializable {

    private static final long serialVersionUID = -3499270912165773476L;
    @Id
    public Long id;

    public Long userId;  //外键 用户id 关联用户

    public String groupId; //分组id
    public String name;     //名称

    public String avatar;   //头像 暂时用不到
    public String remark;  //备注

    public String extra1;  //扩展字段1
    public String extra2;  //扩展字段2
    public String extra3;  //扩展字段3

    @ToMany(referencedJoinProperty = "groupId")
    public List<MemberEntity> list;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 1615357719)
    private transient GroupEntityDao myDao;


    @Generated(hash = 457610197)
    public GroupEntity(Long id, Long userId, String groupId, String name,
            String avatar, String remark, String extra1, String extra2,
            String extra3) {
        this.id = id;
        this.userId = userId;
        this.groupId = groupId;
        this.name = name;
        this.avatar = avatar;
        this.remark = remark;
        this.extra1 = extra1;
        this.extra2 = extra2;
        this.extra3 = extra3;
    }

    @Generated(hash = 954040478)
    public GroupEntity() {
    }


    @Override
    public String toString() {
        return "GroupEntity{" +
                "id=" + id +
                ", userId=" + userId +
                ", groupId='" + groupId + '\'' +
                ", name='" + name + '\'' +
                ", avatar='" + avatar + '\'' +
                ", remark='" + remark + '\'' +
                ", extra1='" + extra1 + '\'' +
                ", extra2='" + extra2 + '\'' +
                ", extra3='" + extra3 + '\'' +
                ", list=" + list +
                '}';
    }

    @Override
    public int getItemType() {
        return ContactsAdapter.TYPE_CONTACT_GROUP;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return this.userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getGroupId() {
        return this.groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAvatar() {
        return this.avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getRemark() {
        return this.remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getExtra1() {
        return this.extra1;
    }

    public void setExtra1(String extra1) {
        this.extra1 = extra1;
    }

    public String getExtra2() {
        return this.extra2;
    }

    public void setExtra2(String extra2) {
        this.extra2 = extra2;
    }

    public String getExtra3() {
        return this.extra3;
    }

    public void setExtra3(String extra3) {
        this.extra3 = extra3;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 417767326)
    public List<MemberEntity> getList() {
        if (list == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            MemberEntityDao targetDao = daoSession.getMemberEntityDao();
            List<MemberEntity> listNew = targetDao._queryGroupEntity_List(id);
            synchronized (this) {
                if (list == null) {
                    list = listNew;
                }
            }
        }
        return list;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 589833612)
    public synchronized void resetList() {
        list = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1578846137)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getGroupEntityDao() : null;
    }


}
